package com.tarena.lbs.basic.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.basic.dao.mapper.TagMapper;
import com.tarena.lbs.basic.dao.repository.TagRepository;
import com.tarena.lbs.basic.pojo.po.TagLibraryPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class TagRepositoryImpl implements TagRepository {
    
    @Autowired
    private TagMapper tagMapper;
    
    @Override
    public List<TagLibraryPO> getTagsByType(Integer tagType) {
        QueryWrapper<TagLibraryPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag_type", tagType)
                   .eq("status", 0) // 只查询启用的标签
                   .orderByAsc("tag_parent_id", "id");
        return tagMapper.selectList(queryWrapper);
    }

    @Override
    public List<TagLibraryPO> getAllEnabledTags() {
        QueryWrapper<TagLibraryPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0) // 只查询启用的标签
                   .orderByAsc("tag_type", "tag_parent_id", "id");
        return tagMapper.selectList(queryWrapper);
    }

    @Override
    public List<TagLibraryPO> getTagsByParentId(Integer parentId) {
        QueryWrapper<TagLibraryPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag_parent_id", parentId)
                   .eq("status", 0) // 只查询启用的标签
                   .orderByAsc("id");
        return tagMapper.selectList(queryWrapper);
    }

    @Override
    public TagLibraryPO getTagById(Integer id) {
        return tagMapper.selectById(id);
    }
}